package com.clstu.ploy_.ployarr_;

public class PloyArray {//对象的多态，多态数组，向上转型
    public static void main(String[] args) {
//        Person[] person=new Person[5];
//        person[0]=new Person("jack",20);
//        person[1]=new Student("Chen",21,80);
//        person[2]=new Student("Ha",20,90);
//        person[3]=new Teacher("Ma",30,10000);
//        person[4]=new Teacher("Xue",50,20000);
//        for (int i = 0; i < person.length; i++) {
//            System.out.println(person[i].say());
//            if(person[i] instanceof Student) ((Student)person[i]).study();//向下转型
//            if(person[i] instanceof Teacher) ((Teacher)person[i]).teach();
//            System.out.println("===========");
//        }
//        //person[3].teach();//报错，编译类型是Person，用不了teach（）方法
//        ((Teacher)person[3]).teach();//向下转型之后就可以使用它的taach方法了ed

    }
}
